package include;

import include.nseer_db.nseer_db;
import include.tree_index.Nseer;
import include.tree_index.businessComment;
import java.sql.ResultSet;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import uk.ltd.getahead.dwr.WebContext;
import uk.ltd.getahead.dwr.WebContextFactory;

public class NseerModuleTreeNode {

    WebContext ctx = WebContextFactory.get();
    HttpSession session = ctx.getSession();
    HttpServletRequest request = ctx.getHttpServletRequest();

    public NseerModuleTreeNode() {
    }

    public String Category(String categoryId, String tablename) {
        businessComment demo = new businessComment();
        demo.setPath(request);
        ServletContext context = session.getServletContext();
        String path = context.getRealPath("/");
        path = path.substring(0, path.length() - 1);
        int index = path.lastIndexOf("\\");
        path = path.substring(index + 1, path.length());
        Nseer n = new Nseer();
        nseer_db db = new nseer_db((String) session.getAttribute("unit_db_name"));
        nseer_db db1 = new nseer_db((String) session.getAttribute("unit_db_name"));
        String return_msg = "";
        String group_name = "erp";
        try {
            String sql = "select * from " + tablename + "_view where PARENT_CATEGORY_ID='" + categoryId + "' and human_ID='" + (String) session.getAttribute("human_IDD") + "' and workflow_tag='0'";
            ResultSet rs = db.executeQuery(sql);
            while (rs.next()) {
                if (rs.getInt("DETAILS_TAG") == 1) {
                    return_msg += "<div style=\"background: transparent url(/" + path + "/images/tree/l.gif) repeat-x 0 -15px;\"><a href=\"javascript:void(0)\" style=\"background-image:url(/" + path + "/images/tree/l.gif);width:100%;\" onMouseOver=\"window.status='powered by nseer erp'; return true\" onclick=\"toggleNode(this.parentNode,'" + rs.getString("CATEGORY_ID") + "','" + tablename + "'); return false;\"  onfocus=\"this.blur()\"><span style=\"padding:0px 0px 0px 3px\"><img src=\"/" + path + "/images/side.gif\" align=\"absmiddle\" style=\"border: 0;\" ></span><span style=\"padding:0px 0px 0px 8px\">" + demo.getLang(group_name, rs.getString("file_name")) + "</span></a></div>";
                } else {
                    if (!rs.getString("hreflink").equals("")) {
                        return_msg += "<div style=\"background:#ffffff;width:100%\" class=\"hrefdiv\"><span style=\"padding:0px 0px 0px 3px\"><img src=\"/" + path + "/images/tree/2.gif\" align=\"absmiddle\" style=\"border: 0;\" ></span><span style=\"padding:0px 0px 0px 8px\"></span><A HREF=\"javascript:void(0);\" onmousedown=\"window.status='powered by nseer erp';this.href='javascript:void(0)';\" onmouseover=\"window.status='powered by nseer erp';this.href='javascript:void(0)'; return true\" onclick=\"changeColor(this,'/" + path + "/" + rs.getString("file_path") + rs.getString("hreflink") + "?readXml=n')\" onfocus=\"this.blur()\" >" + demo.getLang(group_name, rs.getString("file_name")) + "</A></div>";
                    } else {
                        return_msg += "<div style=\"background:#DDEAF6;width:100%\"><span style=\"padding:0px 0px 0px 3px\"><img src=\"/" + path + "/images/bean.JPG\" align=\"absmiddle\" style=\"border: 0;\" ></span><span style=\"padding:0px 0px 0px 8px\"></span>" + demo.getLang(group_name, rs.getString("file_name")) + "</div>";
                    }
                }
            }
            db.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return return_msg;
    }
}
